home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / HD-Installer / jst_dev / sources / src / loaders / jst / jst_deg.asm < prev    next >
Assembly Source File  |  2000-04-12  |  11KB  |  745 lines

  1. ; *** JOTD HD Startup utility library
  2. ; *** Copyright Jean-Francois Fabre 1996-1998
  3. ; *** Sprite degrade part Copyright Bert Jahn 1996
  4.  
  5. ; *** degrader part. Other parts are not distributed
  6.  
  7. ; If you use this source (or parts), I'd appreciate
  8. ; that you credit me about it. Thanks
  9. ;
  10.     ; *** For link with C programs
  11.  
  12. ;;    XDEF    _C_Degrade
  13. ;;    XDEF    _C_Enhance
  14.  
  15. ;;    XDEF    _Enhance
  16. ;;    XDEF    _Degrade
  17. ;;    XDEF    _DegradeCpu
  18. ;;    XDEF    _DegradeGfx
  19.  
  20. ;;    XDEF    _FlushCachesSys
  21.  
  22. ;;    XDEF    _Kick37Test
  23. ;;    XDEF    _KickVerTest
  24.  
  25. RESET_CIA_CODE:MACRO
  26.  
  27. ResetCIAs:
  28.     move.b  #$c0,$bfd200            ;reinit CIAs
  29.     move.b  #$ff,$bfd300            ;for
  30.     move.b  #$03,$bfe201            ;KB
  31. ;    move.b  #$7f,$bfec01
  32.     move.b  #$00,$bfee01
  33.     move.b  #$88,$bfed01
  34.  
  35.     tst.b    $bfdd00            ; acknowledge CIA-B Timer A interrupt
  36.     tst.b    $bfed01            ; acknowledge CIA-A interrupts
  37.  
  38.     bsr    AckKeyboard
  39.  
  40.     rts
  41.  
  42. AckKeyboard:
  43.     bset    #$06,$BFEE01
  44.     move.l    D0,-(A7)
  45.     moveq.l    #1,D0
  46.     IFD    HDSTARTUP
  47.     bsr    RelFun_BeamDelay
  48.     ENDC
  49.     move.l    (A7)+,D0
  50.     bclr    #$06,$BFEE01
  51.     rts
  52.     ENDM
  53.  
  54.     IFND    HDSTARTUP
  55.  
  56.     ; *** this code is on its own (which is the case :-) )
  57.     
  58. _SysBase = 4
  59.  
  60.     include    "libs.i"
  61.     include    "jst_macros.i"
  62.  
  63.     ENDC
  64.  
  65.  
  66. ; *** Restore degraded things: Display, Caches, VBR...
  67.  
  68. ; internal use (in InGameExitAbs)
  69.  
  70. ;;_C_Enhance:
  71. ;;_Enhance:
  72. AbsFun_Enhance:
  73.     STORE_REGS
  74.  
  75.     tst.b    degraded_cpu
  76.     beq    skipec$
  77.  
  78.     move.l    oldcacheset(pc),D0
  79.     moveq.l    #-1,D1
  80.     bsr    EnaCaches
  81.  
  82.     move.l    oldvbr(pc),D0
  83.     bsr    SetVBR
  84.  
  85. skipec$
  86.     tst.b    degraded_gfx
  87.     beq    exit$
  88.  
  89.     move.l    _SysBase,A6
  90.     JSRLIB    Disable
  91.  
  92.     move.l    _GfxBase,D0
  93.     beq    1$
  94.  
  95.     lea    $DFF000,A5
  96.     move.l    my_copinit(PC),cop1lc(a5) ; adresse du début de la liste
  97.  
  98.     move.l    D0,A6
  99.  
  100.     bsr    EnhanceBandWidth
  101.  
  102.     move.l    my_actiview(PC),D0
  103.     beq    1$
  104.     move.l    D0,A1
  105.  
  106.     JSRLIB    LoadView
  107.     JSRLIB    WaitTOF
  108.     JSRLIB    WaitTOF
  109.  
  110. 1$
  111.     move.l    _SysBase,A6
  112.     JSRLIB    Enable
  113.  
  114.     move.l    _IntuitionBase,D0
  115.     beq    skip$
  116.     move.l    D0,A6
  117.     move.l    TheScreen,D0
  118.     beq    skip$
  119.  
  120.     bsr    EnhanceSprites
  121.  
  122.     move.l    TheScreen,D0
  123.     move.l    D0,A0
  124.     move.l    TheScreen,A0
  125.     JSRLIB    CloseScreen
  126.  
  127.     bsr    CloseIntuiLib
  128. skip$
  129.     bsr    CloseGFXLib
  130. exit$
  131.  
  132.     RESTORE_REGS
  133.     rts
  134.  
  135. DegradeBandWidth:
  136.     STORE_REGS
  137.     clr.b    degraded_bdw
  138.     move.l    (_GfxBase),a6
  139.     cmp.l    #39,(LIB_VERSION,a6)
  140.     blo    gfxold$
  141.     btst    #GFXB_AA_ALICE,(gb_ChipRevBits0,a6)
  142.     beq    noaga$
  143.     move.b    (gb_MemType,a6),oldbandwidth
  144.     move.b    #BANDWIDTH_1X,(gb_MemType,a6)    ;auf ECS Wert setzen
  145.     move.l    #SETCHIPREV_A,D0
  146.     JSRLIB    SetChipRev
  147.     move.l    D0,oldchiprev
  148.     st    degraded_bdw
  149. noaga$
  150. gfxold$
  151.     RESTORE_REGS
  152.     rts
  153.  
  154. EnhanceBandWidth:
  155.     STORE_REGS
  156.     tst.b    degraded_bdw
  157.     beq    exit$
  158.  
  159.     move.l    (_GfxBase),a6
  160.  
  161.     move.l    oldchiprev,D0
  162.     JSRLIB    SetChipRev
  163.  
  164.     move.b    oldbandwidth,(gb_MemType,a6)
  165.     clr.b    degraded_bdw
  166. exit$
  167.  
  168.     RESTORE_REGS
  169.     rts
  170.  
  171. AbsFun_DegradeCpu:
  172. _DegradeCpu:
  173.     movem.l    D0/D1,-(sp)
  174.     bsr    GetVBR
  175.     move.l    D0,oldvbr
  176.     bsr    ZeroVBR
  177.     movem.l    (sp)+,D0/D1
  178.     bsr    DisCaches
  179.     move.l    D0,oldcacheset
  180.     move.b    #$00,$DE0000        ; DTack (A3000/A4000 users)
  181.     st.b    degraded_cpu
  182.     rts
  183.  
  184. AbsFun_DegradeGfx:
  185. _DegradeGfx:
  186.     bsr    OpenGFXLib
  187.     beq    D_Exit
  188.  
  189.     bsr    OpenIntuiLib
  190.     beq    D_Exit
  191.  
  192.     move.l    _IntuitionBase,D0
  193.     beq    skip$
  194.     move.l    D0,A6
  195.     sub.l    a0,a0
  196.     lea    ScreenTags,a1
  197.     JSRLIB    OpenScreenTagList
  198.     move.l    d0,TheScreen
  199.  
  200.     ; set sprite to common OCS resolution
  201.  
  202.     move.l    _GfxBase,A6
  203.     cmp.w    #39,(LIB_VERSION,a6)
  204.     blo    skip$
  205.     bsr    DegradeSprites    
  206. skip$
  207.     IFD    HDSTARTUP
  208.     move.l    _DosBase,A6
  209.     move.l    #20,D1
  210.     JSRLIB    Delay        ; wait 2/5 second before launching
  211.     ENDC
  212.  
  213.     move.l    _GfxBase,A6
  214.     move.l    gb_ActiView(A6),my_actiview
  215.     move.l    gb_copinit(A6),my_copinit
  216.     sub.l    A1,A1
  217.     JSRLIB    LoadView
  218.     JSRLIB    WaitTOF
  219.     JSRLIB    WaitTOF
  220. wav$
  221.     tst.l    (gb_ActiView,a6)
  222.     bne.b    wav$
  223.     JSRLIB    WaitTOF
  224.  
  225.     bsr    DegradeBandWidth
  226.  
  227.     IFD    HDSTARTUP
  228.     JSRGEN    ResetDisplay
  229.     ENDC
  230.  
  231.     lea    $DFF000,A5
  232.     move.w    #$0,(bplcon2,A5)
  233.     move.w    #$0,(bplcon3,A5)
  234.     move.w    #$0,(bpl1mod,A5)
  235.     move.w    #$0,(bpl2mod,A5)
  236.  
  237.  
  238. D_Exit:
  239.     st.b    degraded_gfx
  240.     rts
  241.  
  242. ; *** degrade the sprites
  243. ; *** thanks to Bert Jahn for the routine!!
  244.  
  245. DegradeSprites:
  246.     move.l    TheScreen,A0
  247.     move.l    (sc_ViewPort+vp_ColorMap,a0),a0
  248.     clr.l    -(a7)            ;TAG_DONE
  249.     clr.l    -(a7)
  250.     move.l    #VTAG_SPRITERESN_GET,-(a7)
  251.     move.l    a7,a1
  252.     move.l    _GfxBase,a6
  253.     JSRLIB    VideoControl
  254.     addq.l    #4,a7
  255.     lea    oldspriteres,a0
  256.     move.l    (a7)+,(a0)
  257.     addq.l    #4,a7
  258.     
  259.     move.l    TheScreen,a0
  260.     move.l    (sc_ViewPort+vp_ColorMap,a0),a0
  261.     clr.l    -(a7)            ;TAG_DONE
  262.     move.l    #SPRITERESN_140NS,-(a7)
  263.     move.l    #VTAG_SPRITERESN_SET,-(a7)
  264.     move.l    a7,a1
  265.     JSRLIB    VideoControl
  266.     lea    (12,a7),a7
  267.  
  268.     move.l    TheScreen,a0
  269.     move.l    _IntuitionBase,a6
  270.     JSRLIB    MakeScreen    ;force the changes
  271.     JSRLIB    RethinkDisplay
  272.  
  273.     st.b    degraded_spr
  274.     rts
  275.  
  276. EnhanceSprites:
  277.     tst.b    degraded_spr
  278.     beq    exit$
  279.  
  280.     move.l    _GfxBase,A6
  281.     move.l    TheScreen,a0
  282.     move.l    (sc_ViewPort+vp_ColorMap,a0),a0
  283.     clr.l    -(a7)            ;TAG_DONE
  284.     move.l    oldspriteres,-(a7)
  285.     move.l    #VTAG_SPRITERESN_SET,-(a7)
  286.     move.l    a7,a1
  287.     JSRLIB    VideoControl
  288.     lea    (12,a7),a7
  289.  
  290.     move.l    TheScreen,a0
  291.     move.l    _IntuitionBase,a6
  292.     JSRLIB    MakeScreen    ;force the changes
  293.  
  294.     clr.b    degraded_spr
  295. exit$
  296.     rts
  297.  
  298. ; *** Degrades everything
  299. ; in: D0,D1: value and mask for caches control
  300. ; (the same format as in CacheControl())
  301.  
  302. _C_Degrade:
  303.     move.l    4(A7),D0
  304.     move.l    8(A7),D1
  305. _Degrade:
  306. AbsFun_Degrade:
  307.     STORE_REGS
  308.  
  309.     move.l    D0,user_cacheflags
  310.     move.l    D1,user_cachemask
  311.  
  312.     bsr    _DegradeCpu        ; degrades caches, VBR, dtack
  313.     bsr    _DegradeGfx        ; degrades sprites and screen
  314.     bsr    ResetCIAs        ; re-init keyboard
  315.  
  316.     RESTORE_REGS
  317.     rts
  318.  
  319. DisCaches:
  320.     movem.l    D1-A6,-(sp)
  321.  
  322.     move.l    D0,D6
  323.     move.l    D1,D7
  324.  
  325.     bsr    _Kick37Test
  326.     tst.l    D0
  327.     bne    3$        ; Don't touch if KS 1.x
  328.  
  329.     move.l    D6,D0
  330.     move.l    D7,D1
  331.  
  332.     IFD    HDSTARTUP
  333.     tst.l    leavecaches_flag
  334.     bne    3$        ; Don't touch the caches
  335.     tst.l    nocaches_flag
  336.     beq    5$        ; Disable ALL caches
  337.     ENDC
  338.  
  339.     moveq.l    #0,D0
  340.     moveq.l    #-1,D1
  341. 5$
  342.     move.l    _SysBase,A6
  343.     JSRLIB    CacheControl
  344.     move.l    D0,D7
  345.  
  346.     move.l    _SysBase,A6
  347.     move.b    AttnFlags+1(A6),D0
  348.     btst    #AFB_68060,D0
  349.     beq    2$
  350.  
  351.     ; *** remove data cache, branch cache, write cache, superscalar mode
  352.  
  353.     lea    DisCacheSup,A5
  354.     move.l    _SysBase,A6
  355.     JSRLIB    Supervisor
  356. 2$
  357.     move.l    D7,D0
  358.     movem.l    (sp)+,D1-A6
  359.     rts
  360.  
  361. 3$
  362.     moveq.l    #0,D0
  363.     bra    2$
  364.  
  365. EnaCaches:
  366.     movem.l    D1-A6,-(sp)
  367.  
  368.     IFD    HDSTARTUP
  369.     tst.l    leavecaches_flag
  370.     bne    3$        ; Don't touch the caches
  371.     ENDC
  372.  
  373.     move.l    D0,D7
  374.     bsr    _Kick37Test
  375.     tst.l    D0
  376.     bne    3$        ; Don't touch if KS 1.x
  377.     move.l    D7,D0
  378.     move.l    _SysBase,A6
  379.     JSRLIB    CacheControl
  380.  
  381.     move.l    D0,D7
  382.  
  383.     move.l    _SysBase,A6
  384.     move.b    AttnFlags+1(A6),D0
  385.     btst    #AFB_68060,D0
  386.     beq    2$
  387.  
  388.     lea    EnaCacheSup,A5
  389.     move.l    _SysBase,A6
  390.     JSRLIB    Supervisor
  391. 2$
  392.     move.l    D7,D0
  393.     movem.l    (sp)+,D1-A6
  394.     rts
  395.  
  396. 3$
  397.     moveq.l    #0,D0
  398.     bra    2$
  399.  
  400. ; *** Disable some '060 caches
  401. ; *** Left intact by CacheControl
  402.  
  403. ; internal, only useful (and executed) for 68060 cpus
  404.  
  405. DisCacheSup:
  406.     movem.l    D1-A6,-(sp)
  407.     MACHINE    68060
  408.     ori.w    #$700,sr
  409.     movec    cacr,D0
  410.     andi.l    #$A0800000,D0
  411.     move.l    D0,old060cacr
  412.  
  413.     movec    cacr,D0
  414.     move.l    #$A0800000,D1        ; mask for specific 68060 caches
  415.  
  416.     not.l    D1
  417.     and.l    D1,D0
  418.     movec    D0,cacr
  419.  
  420.     nop
  421.  
  422.     ; *** remove superscalar
  423.  
  424.     bra    nossh$
  425.     movec    pcr,D0
  426.     move.l    D0,old060pcr
  427.     andi.l    #$04300100,D0
  428.     movec    D0,pcr
  429. nossh$
  430.  
  431.     ; *** flush
  432.  
  433.     CPUSHA    BC
  434.     movem.l    (sp)+,D1-A6
  435.     MACHINE    68000
  436.     rte
  437.  
  438. ; *** Enable some '060 caches
  439. ; *** Left intact by CacheControl
  440.  
  441. EnaCacheSup:
  442.     MACHINE    68060
  443.     ori.w    #$700,sr
  444.     movec    cacr,D0
  445.     or.l    old060cacr,D0
  446.     movec    D0,cacr
  447.  
  448.     bra    nossh$
  449.     movec    pcr,D0
  450.     or.l    old060pcr,D0
  451.     movec    D0,pcr
  452. nossh$
  453.  
  454.     CPUSHA    BC
  455.     MACHINE    68000
  456.     rte
  457.  
  458. ; *** Gets VBR value
  459. ; out: D0: VBR value
  460.  
  461. ; VBR is the vector base register (interrupts, traps, exceptions)
  462. ; It exists on 68010, 68020, 68030, 68040, 68060
  463. ; Most of the games don't like it to be different from zero,
  464. ; others are originally HD-Installable :-)
  465. ; Called from a 68000, this function will return 0 in any case (no VBR)
  466.  
  467. GetVBR:
  468.     movem.l    D1-A6,-(sp)
  469.     lea    GetVBRSup,A0
  470.     bsr    OperateVBR
  471.     movem.l    (sp)+,D1-A6
  472.     rts
  473.  
  474. ; *** Sets VBR value
  475. ; in: D0: new VBR value
  476.  
  477. ; Called from a 68000, this function will do nothing (no VBR)
  478. ; It will do nothing if the LEAVEVBR tooltype is set too (debug)
  479.  
  480. SetVBR:
  481.     movem.l    D1-A6,-(sp)
  482.     lea    SetVBRSup,A0
  483.     bsr    OperateVBR
  484.     movem.l    (sp)+,D1-A6
  485.     rts
  486.     
  487. ; *** Sets VBR to zero
  488. ; It will do nothing if the LEAVEVBR tooltype is set (debug)
  489.  
  490. ZeroVBR:
  491.     movem.l    D1-A6,-(sp)
  492.     moveq.l    #0,D0
  493.     bsr    SetVBR
  494.     movem.l    (sp)+,D1-A6
  495.     rts
  496.  
  497. ; *** VBR operation
  498. ; in: A0: supervisor function to call
  499. ;     D0: value to pass to the sup function
  500. ; out D0: return val of the sup function
  501.  
  502. ; It will do nothing if the LEAVEVBR tooltype is set